<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*"  %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.lang.System" %>
<%@ page import="twitter4j.*" %>
<%@ page import="twitter4j.http.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko"> 
<head>
<title>home time line</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
  <%
  //App Key 지정. App을 등록한 후 발급받은 키를 입력
  String CONSUMER_KEY = "lLDr77zex3PnPUV5bI9ow";
  String CONSUMER_SECRET = "LZQ9bR9MR2eiknDeJsTpfCaCZvQSRnBXRK56D9prx0";
  //페이징을 위한 사전작업, 페이지당 30개의 게시물
  int pageNum = 1;
  int pageSize = 30;
  if(pageNum == 0)
   pageNum = 1;
  //트위터 객체 생성
  Twitter twitter = new Twitter();
  twitter.setOAuthConsumer(CONSUMER_KEY,CONSUMER_SECRET);
  twitter.setOAuthAccessToken((AccessToken)session.getAttribute("AccessToken"));
  //페이징을 통한 타임라인 불러오기
  Paging pages = new Paging(pageNum, pageSize);

  List statuses = twitter.getHomeTimeline(pages);
  
  //멘션을 불러오고 싶으면 getMentions 를 이요하시면 되겠네요.
  //List statuses = twitter.getMentions(pages);
  String imgUrl = "";
  String usrName = "";
  String scrName = "";
  String contents = "";
  String strHTML = "";
  String strCreate = "";
  String strSource = "";
  String sID = "";
  //날짜형식 변환하기
  Locale locale = Locale.US;
  SimpleDateFormat sdf = new SimpleDateFormat("h:mm a MMM d'th'", locale);
  for(int i=0; i < statuses.size(); i++)
  {
   Status status = (Status)statuses.get(i);
   imgUrl = "";
   usrName = "";
   scrName = "";
   contents = "";
   strHTML = "";
   strCreate = "";
   strSource = "";
   sID = "";
   imgUrl = status.getUser().getProfileImageURL().toString();
   usrName = status.getUser().getName();
   scrName = status.getUser().getScreenName();
   strCreate = sdf.format(status.getCreatedAt()).toString();
   strSource = status.getSource();
   sID = String.valueOf(status.getId());
   contents = status.getText();
  %>
  <img src="<%=imgUrl%>" width="48" height="48" alt="" /><br>
  <a href="http://twitter.com/<%=scrName%>" target="_blank" id="idName" class="name_off"><%=scrName%></a> (<%=usrName %>) <%=strCreate%> via <%=strSource%><br>
  <%=contents%><br><br>
  <%
  }
  %>
</body>
</html>